package com.test.blibrary;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.test.aninterface.IPrint;
import com.test.aninterface.spiFactory;
import com.test.aninterface.startIntent;

import java.util.ServiceLoader;

public class BMainActivity extends AppCompatActivity implements View.OnClickListener{
    private Button btn_B,btn_to_A,btn_to_app;
    private spiFactory<startIntent> spiFactory;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bmain);
        spiFactory = new spiFactory<>(startIntent.class);
        btn_B = findViewById(R.id.B_btn);
        btn_to_A = findViewById(R.id.BtnToA);
        btn_to_app = findViewById(R.id.BtnToApp);
        btn_B.setTag("B");
        btn_to_A.setTag("A");
        btn_to_app.setTag("App");
        btn_B.setOnClickListener(this);
        btn_to_A.setOnClickListener(this);
        btn_to_app.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        String name = (String) view.getTag();
        switch (name){
            case "B":
                goB();
                break;
            case "A":
                goA();
                break;
            case "App":
                goApp();
                break;
        }
    }
    public void goB(){
        startIntent iPrint = spiFactory.getObject("goBImp");
        if(iPrint != null){
            iPrint.go("b");
        }
    }
    public void goA(){
        startIntent iPrint = spiFactory.getObject("goAImp");
        if(iPrint != null){
            iPrint.go("a");
        }
    }
    public void goApp(){
        startIntent iPrint = spiFactory.getObject("goMainActivity");
        if(iPrint != null){
            iPrint.go("app");
        }
    }
}